package ml.util;

/**
 * 分页工具：计算总页数
 * 1.总数量/每页显示几条
 */
public class PageSupport {
    //当前页码
    private int currentPageNo = 1;
    //总数量
    private int totalCount = 0;
    //当前容量
    private int pageSize = 0;
    //总页数
    private int totalPageCount = 1;

    public PageSupport() {
    }

    public PageSupport(int currentPageNo, int totalCount, int pageSize, int totalPageCount) {
        this.currentPageNo = currentPageNo;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.totalPageCount = totalPageCount;
    }

    public int getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(int currentPageNo) {
        if(currentPageNo>0)
        this.currentPageNo = currentPageNo;
    }

    public int getTotalCount() {
        return totalCount;
    }
    //计算总页数
    public void getTotalPageCountByRS(){
        if(this.totalCount%this.pageSize==0){
            this.totalPageCount = this.totalCount/this.pageSize;
        }else if(this.totalCount%this.pageSize!=0){
                this.totalPageCount = this.totalCount/this.pageSize+1;
        }
    }
    //总数量 设置总数量是，同步计算出总页数
    public void setTotalCount(int totalCount) {
        if(totalCount>=0) {
            this.totalCount = totalCount;
            this.getTotalPageCountByRS();
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        if(pageSize>0)
        this.pageSize = pageSize;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }
}
